﻿/*
 * Created by SharpDevelop.
 * User: dol
 * Date: 16/6/2556
 * Time: 7:43
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Runtime.InteropServices;

namespace titi.utilkey
{
	/// <summary>
	/// Description of Class1.
	/// </summary>
	sealed public class SimKeyPress
	{
		[DllImport("user32.dll", SetLastError = true)]
		static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		public SimKeyPress()
		{
		}
		
		public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
		public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
		public const int VK_LCONTROL = 0xA2; //Left Control key code
		public const int A = 0x41; //A Control key code
		public const int C = 0x43; //A Control key code
		
		public static void KeyPress_CtrlA_Then_CtrC()
		{
		    // Hold Control down and press A
		    keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
		    keybd_event(A, 0, KEYEVENTF_EXTENDEDKEY, 0);
		    keybd_event(A, 0, KEYEVENTF_KEYUP, 0);
		    keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
		
		    // Hold Control down and press C
		    keybd_event(VK_LCONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
		    keybd_event(C, 0, KEYEVENTF_EXTENDEDKEY, 0);
		    keybd_event(C, 0, KEYEVENTF_KEYUP, 0);
		    keybd_event(VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0);
		}		
		
	}
}
